// 订单管理组件
<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/mangerHome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区 -->
    <el-card >
      <!-- 搜索区 gutter设置列间距 span设置列的大小-->
      <el-row :gutter="10">
        <!-- 搜索订单 -->
        <el-col :span="16">
          <el-input placeholder="请输入内容" v-model="querInfo.query" clearable @clear="getOrderList">
            <el-button slot="append" icon="el-icon-search" @click="getOrderList" ></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格 商品列表 -->
      <el-table :data="orderList" border stripe>
        <el-table-column type="index" label="#"></el-table-column> <!-- 索引列 -->
        <el-table-column label="订单编号" prop="order_number"></el-table-column> 
        <el-table-column label="订单价格" prop="order_price" width="90px"></el-table-column> 
        <el-table-column label="是否付款" prop="order_pay" width="90px">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.order_pay==='0'">未付款</el-tag>
            <el-tag type="success" v-else>已付款</el-tag>
          </template>
        </el-table-column> 
        <el-table-column label="是否发货" prop="is_send" width="90px">
           <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.is_send==='否'">否</el-tag>
            <el-tag type="success" v-else>是</el-tag>
          </template>
        </el-table-column> 
        <el-table-column label="下单时间" prop="create_time" width="150px">
          <template slot-scope="scope">
           {{scope.row.create_time | dateFormat}}
          </template>
        </el-table-column> 
        <el-table-column label="操作" width="140px">
          <template>
<!-- 编辑 --><el-button type="primary" icon="el-icon-edit" size="mini" @click="editDialogVisible=true"></el-button>
<!-- 删除 --><el-button type="success" icon="el-icon-s-promotion" @click="showProgress" size="mini"></el-button>
          </template>
        </el-table-column> 
      </el-table>
       <!-- 分页区 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
      :current-page="querInfo.pagenum" :page-sizes="[5, 10, 15, 20]" :page-size="querInfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </el-card>
    <!-- 编辑订单弹出来的对话框 -->
    <el-dialog title="编辑地址" :visible.sync="editDialogVisible" width="50%" @close="editDialogVisibleClose">
    <!-- 表单区 -->
      <el-form :model="addressForm" :rules="addressFormRules" ref="addressFormRef" label-width="100px">
        <el-form-item label="省市区/县:" prop="address1">
          <!-- 级联框  options指定数据源-->
          <el-cascader v-model="addressForm.address1" :options="CityDate" expand-trigger="hover" clearable change-on-select></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" >确 定</el-button>
      </span>
    </el-dialog>
    <!-- 查看物流弹出来的对话框 -->
    <el-dialog title="物理信息" :visible.sync="progressDialogVisible" width="50%">
      <!-- <el-timeline >
        <el-timeline-item v-for="(activity, index) in progressInfo" :key="index" :timestamp="activity.time">
          {{activity.context}}
        </el-timeline-item>
      </el-timeline> -->
    </el-dialog>
  </div>
</template>

<script>
import CityDate from './js/citydata.js'
export default {
  data() {
    return {
      querInfo:{   //访问后端用户数据所传参数对象
        query: '',    //搜索用户的关键字
        pagenum: 1,  //当前所在页数
        pagesize: 5  //每页显示多少条数据
      },  
      total:0,     //数据总条数
      orderList:[],   //
      CityDate,    //城市信息
      editDialogVisible:false,    //编辑对话框显示/隐藏
      addressForm:{   //编辑订单地址绑定的数据
        address1:[],   //省市区
        address2:'',   //详细地址
      },
      addressFormRules:{   //编辑订单地址绑定的验证规则
        address1:[
          { required: true, message: '请选择省市区', trigger: 'blur' }
        ],
        address2:[
          { required: true, message: '请输入详细地址', trigger: 'blur' }
        ]
      },
      progressDialogVisible:false,   //物理信息对话框
      progressInfo:[],   //物理信息
    }
  },
  created() {
    this.getOrderList()
  },
  methods: {
    async getOrderList(){
      const {data:res} = await this.$http.get('/orders',{params:this.querInfo})
      if(res.meta.status !== 200){
        return this.$message.error('访问后台数据失败，无法获取到订单列表！')
      }
      // console.log(res)
      // 请求成功
      this.total = res.data.total
      this.orderList = res.data.goods
    },
    handleSizeChange(newSize){   //监听当pagesize每页显示多少条数据改变时
      this.querInfo.pagesize = newSize  
      this.getOrderList()  //重新发送请求
    },
    handleCurrentChange(newSize){  //监听当pagenum当前显示页数号改变时
      this.querInfo.pagenum = newSize  
      this.getOrderList()  //重新发送请求
    },
    editDialogVisibleClose(){   //监听对话框关闭
      this.$refs.addressFormRef.resetFields()  //表单重置
    },
    async showProgress(){    //显示物流对话框
      // const {data:res} = await this.$http.get('/kuaidi/804909574412544580')
      // console.log(res)    //访问不成功
      // if(res.meta.status !== 200){
      //   return this.$message.error('访问后台数据失败，无法获取到对应物流信息！')
      // }
      this.progressDialogVisible = true
      // this.progressInfo = res.data
    }
  },
}
</script>

<style scoped>
.el-cascader{
  width:100%;
}
</style>